package com.tz.yiqingapp.controller.common;

import com.tz.yiqingapp.bean.DiabetesBean;
import com.tz.yiqingapp.services.dao.CommandServiceImpl;
import com.tz.yiqingapp.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RestController
@RequestMapping("/predict")
public class PredictController {


    @Autowired
    CommandServiceImpl commandService;

    @PostMapping("/diabetes")
    public HashMap<String,Object> login (@RequestBody DiabetesBean diabetesBean, HttpServletRequest request){

        String result =  commandService.executeCmd("cd predict ; python3 dtree_disase.py "
                + diabetesBean.getP1() + " "
                + diabetesBean.getP2() + " "
                + diabetesBean.getP3() + " "
                + diabetesBean.getP4() + " "
                + diabetesBean.getP5() + " "
                + diabetesBean.getP6() + " "
                + diabetesBean.getP7() + " "
                + diabetesBean.getP8() + " " );
        return ResponseUtils.success(result.substring(result.length() - 2, 1));
    }
}
